/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sessionbean;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import supportlearning.entities.StudentResult;

/**
 *
 * @author Huy
 */
@Stateless
public class StudentResultFacade extends AbstractFacade<StudentResult> implements StudentResultFacadeLocal {

    @PersistenceContext(unitName = "EprojectCMSSupportLearning-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public StudentResult findbyStuID(String id, int assid) {

        Query q = em.createQuery("SELECT s FROM StudentResult s WHERE s.studentResultPK.studentId = :a and s.studentResultPK.asmId = :b");
        q.setParameter("a", id);
        q.setParameter("b", assid);
        StudentResult obj = (StudentResult) q.getSingleResult();
        return obj;
    }

    public List<StudentResult> ViewMark(String stuid, int subid) {
        Query q = em.createQuery("SELECT s FROM StudentResult s WHERE s.studentProfile.studentId = :a and s.assignment.subject.subId = :b");
        q.setParameter("a", stuid);
        q.setParameter("b", subid);
        List<StudentResult> listStudentRS = q.getResultList();
        return listStudentRS;
    }

    public List<StudentResult> findbySubid(int subid) {

        Query q = em.createQuery("SELECT s FROM StudentResult s WHERE s.assignment.asmId = :a ");
        q.setParameter("a", subid);

        List<StudentResult> list = q.getResultList();
        return list;
    }

    public List<StudentResult> MarkbyStaff(int assgid) {
        Query q = em.createQuery("SELECT s FROM StudentResult s WHERE s.assignment.asmId = :a");
        q.setParameter("a", assgid);
        List<StudentResult> listStudentRS = q.getResultList();
        return listStudentRS;
    }

    public StudentResultFacade() {
        super(StudentResult.class);
    }
}
